import 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher.dart';
import '../MyButton.dart';
class UrlLauncherPage extends StatefulWidget {
  UrlLauncherPage({Key key}) : super(key: key);

  _UrlLauncherPageState createState() => _UrlLauncherPageState();
}

class _UrlLauncherPageState extends State<UrlLauncherPage> {

 _launch(value) async{
    if(await canLaunch(value)){
      await launch(value);
    }else{
      throw 'Could not launch $value';
    }
 }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("UrlLauncherPage"),
      ),
      body: Column(
        children: <Widget>[
          MyButton(text: '打开外部浏览器',pressed: () async{
            _launch('https://www.baidu.com');
          },),
          MyButton(text: '拨打电话',pressed: () async{
            _launch('tel:10086');
          },),
          MyButton(text: '发送短信',pressed: (){
            _launch('sms:chenxiubin1@qq.com');
          },),
          MyButton(text: '打开外部应用',pressed: (){
            _launch('qq://');
          },)
        ],
      ),
    );
  }
}